import request from '@/utils/request'

export function getAllList() {
  return request({
    url: '/api/identity/organization-units/all',
    method: 'get'
  })
}

export function getById(id) {
  return request({
    url: '/api/identity/organization-units/' + id,
    method: 'get'
  })
}

export function create(dto) {
  return request({
    url: '/api/identity/organization-units',
    method: 'post',
    data: dto
  })
}

export function edit(id, dto) {
  return request({
    url: '/api/identity/organization-units/' + id,
    method: 'put',
    data: dto
  })
}

export function move(id, dto) {
  return request({
    url: '/api/identity/organization-units/' + id + '/move',
    method: 'put',
    data: dto
  })
}

export function deleteById(id) {
  return request({
    url: '/api/identity/organization-units/' + id,
    method: 'delete'
  })
}

// member
export function getMemberList(ouId, params) {
  return request({
    url: '/api/identity/organization-units/' + ouId + '/members',
    method: 'get',
    params
  })
}

export function addMember(ouId, data) {
  return request({
    url: '/api/identity/organization-units/' + ouId + '/members',
    method: 'put',
    data: data
  })
}

export function deleteMember(ouId, memberId) {
  return request({
    url: '/api/identity/organization-units/' + ouId + '/members/' + memberId,
    method: 'delete'
  })
}

// role
export function getRoleList(ouId, params) {
  return request({
    url: '/api/identity/organization-units/' + ouId + '/roles',
    method: 'get',
    params
  })
}

export function addRole(ouId, data) {
  return request({
    url: '/api/identity/organization-units/' + ouId + '/roles',
    method: 'put',
    data: data
  })
}

export function deleteRole(ouId, roleId) {
  return request({
    url: '/api/identity/organization-units/' + ouId + '/roles/' + roleId,
    method: 'delete'
  })
}
